import { defineStore } from "pinia"

interface IRoutes {
  name: string
  path: string
  component: string
  [propName: string]: any
}
export const userStore = defineStore({
  id: "userStore",
  persist: {
    enabled: true,
  },
  state: () => {
    return {
      userInfo: {
        token: "",
        // token: "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhbmRtaW4xNDciLCJ0ZW5hbnRJZCI6Ii0xIiwiZXhwIjoxNjcyMTI3MzgwLCJpYXQiOjE2NzIwNDA5ODB9.2ISyDtPNItf3T-5hpVDUvMqJh8aQSf3aUZI7-MWV3equGBySMmj_fBEfmds630nrcforZCTb6o2af0qxh6gDoQ",
        username: "张三",
        account: "andmin147",
        userId: "1557991857848455168",
        expiration: 86400,
        loginStatus: true,
        userAttrs: { tenantId: "-1" },
        loginTime: 1672040980642,
      },

      //动态路由表
      routesMap: [],

      //是否直接刷新页面
      isReferPage: false,

      spinning: false, // loading标识
    }
  },
  actions: {
    //设置水印状态
    setUserInfo(data: object): void {
      this.userInfo = data
    },

    // 退出
    setSignout(): void {
      console.log(1)
    },

    //刷新token
    referToken(): void {
      console.log(1)
    },

    setRoutesMap(routes: Array<IRoutes>): void {
      this.routesMap = routes || []
    },

    setIsRefer(flag: boolean): void {
      this.isReferPage = flag
    },
  },
})
